#include "mock_transport.h"

MockTrans::MockTrans(kchannel_ref_t* channel) {
    channel_ = knet_channel_ref_share(channel);
}

MockTrans::~MockTrans() {
    knet_channel_ref_leave(channel_);
}

int MockTrans::send(const char* data, int size) {
    auto* stream = knet_channel_ref_get_stream(channel_);
    return knet_stream_push(stream, data, size);
}

int MockTrans::peek(char* data, int size) {
    auto* stream = knet_channel_ref_get_stream(channel_);
    return knet_stream_copy(stream, data, size);
}

int MockTrans::recv(char* data, int size) {
    auto* stream = knet_channel_ref_get_stream(channel_);
    return knet_stream_pop(stream, data, size);
}

int MockTrans::skip(int size) {
    auto* stream = knet_channel_ref_get_stream(channel_);
    return knet_stream_eat(stream, size);
}

int MockTrans::size() {
    auto* stream = knet_channel_ref_get_stream(channel_);
    return knet_stream_available(stream);
}

bool MockTrans::isClose() {
    return (knet_channel_ref_check_close(channel_) != 0) ? true : false;
}

void MockTrans::close() {
    knet_channel_ref_close(channel_);
}
